package com.ctshk.app.order.airexpress.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.airexpress.service.IAirportExpressOrderAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 机场快线 - 订单中心 - 订单详情 缓存控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-23
 */
@Slf4j
@RestController
@RequestMapping("/air/express/es")
@Api(value = "机场快线订单服务-ES", tags = "机场快线订单服务-ES")
public class AirExpressOrderElasticSearchController extends BaseController {

    @DubboReference
    IAirportExpressOrderAppService airportExpressOrderAppService;

    @ApiOperation(value = "机场快线-订单中心-缓存-初始化", notes = "机场快线-订单中心-缓存-初始化")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "机场快线-订单中心-缓存-初始化", operDesc = "机场快线-订单中心-缓存-初始化")
    @GetMapping("/cache/init")
    public Result cacheInit() {
        return airportExpressOrderAppService.airExpressOrderDetailsInit();
    }

    @ApiOperation(value = "机场快线-订单中心-缓存-添加", notes = "机场快线-订单中心-缓存-添加")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "机场快线-订单中心-缓存-更新", operDesc = "机场快线-订单中心-缓存-更新")
    @PostMapping("/cache/add")
    public Result cacheAdd(@Valid @RequestBody List<Long> ids) {
        return airportExpressOrderAppService.airExpressOrderDetailsUpLoad(ids);
    }

    @ApiOperation(value = "机场快线-订单中心-缓存-更新", notes = "机场快线-订单中心-缓存-更新")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "机场快线-订单中心-缓存-更新", operDesc = "机场快线-订单中心-缓存-更新")
    @PostMapping("/cache/update")
    public Result cacheUpdate(@Valid @RequestBody List<Long> ids) {
        return airportExpressOrderAppService.cacheUpdate(ids);
    }

    @ApiOperation(value = "机场快线-订单中心-缓存-按照订单id删除", notes = "机场快线-订单中心-缓存-按照订单id删除")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "机场快线-订单中心-缓存-按照订单id删除", operDesc = "机场快线-订单中心-缓存-按照订单id删除")
    @PostMapping("/cache/delete")
    public Result cacheDelete(@Valid @RequestBody List<Long> ids) {
        return airportExpressOrderAppService.cacheDelete(ids);
    }

    @ApiOperation(value = "机场快线-订单中心-缓存-删除缓存索引", notes = "机场快线-订单中心-缓存-删除缓存索引")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "机场快线-订单中心-缓存-删除缓存索引", operDesc = "机场快线-订单中心-缓存-删除缓存索引")
    @PostMapping("/cache/delete/all")
    public Result cacheDelete() {
        return airportExpressOrderAppService.cacheDeleteAll();
    }

}
